<template>
  <div class="product-list">
    <h2>商品列表</h2>
    <div class="product" v-for="product in products" :key="product.id">
      <h3>{{ product.name }}</h3>
      <p>价格: ￥{{ product.price }}</p>
      <button @click="addToCart(product)">添加到购物车</button>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'

export default {
  name: 'ProductList',
  data() {
    return {
      products: [
        { id: 1, name: '商品A', price: 20 },
        { id: 2, name: '商品B', price: 30 },
        { id: 3, name: '商品C', price: 40 }
      ]
    }
  },
  methods: {
    ...mapActions(['addToCart'])
  }
}
</script>

<style scoped>
.product-list {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

.product {
  border: 1px solid #ccc;
  padding: 1em;
  margin: 1em;
  width: 200px;
  text-align: center;
}
</style>